package com.lonewalker.completablefuturedemo;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author LoneWalker
 * @date 2023/2/12
 * @description
 */
public class demo5 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> completableFuture1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("supplyAsync执行");
            int a =1/0;
            return 5;
        }).handle((result,exception) ->{
            System.out.println("handle执行");
            if (exception != null){
                System.out.println(exception.getMessage());
            }
            if (result != null){
                return result+5;
            }else {
                return 5;
            }
        });

        System.out.println(completableFuture1.get());
    }
}
